package cn.fzkj.project.system.service.impl;

import cn.fzkj.common.utils.StringUtils;
import cn.fzkj.project.system.constant.CategoryByCons;
import cn.fzkj.project.system.domain.SysSummary;
import cn.fzkj.project.system.mapper.SysSummaryMapper;
import cn.fzkj.project.system.service.ISysSummaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/** 总结 业务层处理 */
@Service
public class SysSummaryServiceImpl implements ISysSummaryService {

    @Autowired
    private SysSummaryMapper summaryMapper;

    /** 查询 */
    @Override
    public List<SysSummary> selectList(SysSummary summary) {
        return summaryMapper.selectList(summary);
    }

    /** 新增 */
    @Override
    public int insertSummary(SysSummary summary) {
        if (null == summary.getsId() || ("").equals(summary.getsId())) return summaryMapper.insertSummary(summary);
        return summaryMapper.updateSummary(summary);
    }

    /** 查询没有写的 */
    @Override
    public List<String> selectListEmailOfNotWrite() {
        return summaryMapper.selectListEmailOfNotWrite();
    }

    /** 询所有没有写的用户id */
    @Override
    public List<Long> selectListUserIdOfNotWrite() {
        return summaryMapper.selectListUserIdOfNotWrite();
    }

    /** 查询自动写
     * @param categoryBy 分类方式
     * */
    @Override
    public List<SysSummary> selectListAuto(String categoryBy, Long userId) {
        // 分类方式为空/周
        if (StringUtils.isEmpty(categoryBy) || StringUtils.equals(CategoryByCons.WEEK, categoryBy))
            return summaryMapper.selectListAutoByWeek(userId);
        // 分类方式为月
        if (StringUtils.equals(CategoryByCons.MONTH, categoryBy)) {
            return summaryMapper.selectListAutoByMonth(userId);
        } else {
            return summaryMapper.selectListAutoByMonth(userId);
        }
    }

    /** 查询手动写
     *  @param categoryBy 分类方式
     *  */
    @Override
    public List<SysSummary> selectListNotAuto(String categoryBy, Long userId) {
        if (StringUtils.isEmpty(categoryBy) || StringUtils.equals(CategoryByCons.WEEK, categoryBy))
            return summaryMapper.selectListNotAutoByWeek(userId);
        // 分类方式为月
        if (StringUtils.equals(CategoryByCons.MONTH, categoryBy)) {
            return summaryMapper.selectListNotAutoByMonth(userId);
        } else {
            return summaryMapper.selectListNotAutoByWeek(userId);
        }
    }

    /**  批量新增 */
    @Override
    public int batchInsert(List<SysSummary> summaries){
        return summaryMapper.batchInsert(summaries);
    }

    /** 修改 */
    @Override
    public int updateSummary(SysSummary summary) {
        return summaryMapper.updateSummary(summary);
    }
}
